package com.org.manhu.chargehelper.tools;

import com.org.manhu.chargehelper.webservice.WebRequestManage;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;

/**
 *
 * @文件名：ServerUtil.java
 * @包名：com.example.errorlog
 * @作者：李朋辉 @ QQ：892839211
 * @创建时间：2014年12月10日 下午5:32:44
 * @描述：
 */
public class ServerUtil {

	public void uploadLog(final Context context, final String content) {
		new Thread() {
			public void run() {
				String  json = WebRequestManage.uploadLog("CatchException", "Exc_Soft",
						getAppName(context), "Exc_Version", "" + Build.VERSION.SDK_INT,
						"Exc_MobileNum", "" + Build.BRAND + " " + Build.MODEL,
						"Exc_Info", content);
			}
		}.start();
	}

	/**
	 * 获取应用程序信息
	 */
	private String getAppName(Context context) {
		try {
			PackageManager packageManager = context.getPackageManager();
			PackageInfo packageInfo = packageManager.getPackageInfo(
					context.getPackageName(), 0);
			int labelRes = packageInfo.applicationInfo.labelRes;

			String version = packageInfo.versionName;
			int code = packageInfo.versionCode;

			return context.getResources().getString(labelRes) + "--" + code
					+ "--" + version;
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
		return null;
	}
}
